<?php
/**
 * Manageaccount_Data_Updateuserdata
 * update user data
 *
 * @author Adrian Stolarski
 */
class Manageaccount_Data_Updateuserdata  implements Manageaccount_Data_Mainable, 
        Manageaccount_Data_Preparable{
    /**
     *
     * @var type $database
     * database handler
     */
    public $database;
    /**
     *
     * @var type $database_query
     * database query handler
     */
    public $database_query;
    
    /**
     * constructor()
     */
    public function __construct() {
        $this->database = new Core_Driver_MysqlImproved;
    }
    
    public function main(array $variables = null) {
        $this->database->connect();
        foreach($variables as $key => $value){
            $variables[$key] = $this->database->escape($value);
        }
        $this->prepare_query($variables);
        //echo $this->database_query;
        $this->database->prepare($this->database_query);
        //echo $this->database_query;
        //die();
        $this->database->query();
        $this->database->dataOperations();
        //echo $this->database_query;
        //die();
    }
    
    /**
     * preapare_query()
     * prepare database query
     * @param array $variables
     */
    public function prepare_query(array $variables = null) {
        $this->database_query = "UPDATE "
                . "users_data"
                . " SET "
                . "user_name='"
                .$variables['user_name'].
                "', user_email='"
                .$variables['user_email'].
                "', user_password='"
                .md5($variables['user_password']).
                "' WHERE "
                . "id="
                .$variables['user_id'].
                ";";
    }

}
